#!/usr/bin/env node

const { execSync } = require("child_process");
const { consoleContext } = require("./src/utils/consoleContext");

const { runVideoBatch } = require("./src/run_video_batch");
const { runVideo } = require("./src/run_video");

const command = process.argv[2];

switch (command) {
  case "convert":
    execSync("node src/convert_all.js", { stdio: "inherit" });
    break;
  case "download-images":
    const downloadArgs = process.argv.slice(3);
    if (downloadArgs.length === 0) {
      execSync("node src/download_images.js 1 100", { stdio: "inherit" });
    } else {
      execSync(`node src/download_images.js ${downloadArgs.join(" ")}`, {
        stdio: "inherit",
      });
    }
    break;
  case "create-video":
    const videoArgs = process.argv.slice(3);
    execSync(`node src/create_video.js ${videoArgs.join(" ")}`, {
      stdio: "inherit",
    });
    break;
  case "run-video-dat":
    runVideo("dat");
    break;
  case "run-video-ass":
    runVideo("ass");
    break;
  case "run-video-bat":
    const folderName = process.argv[3];
    if (!folderName) {
      console.error("！！！错误: 请指定要处理的目录名称");
      console.log('示例: npm run run-video-bat "商务英语300句"');
      process.exit(1);
    }
    runVideoBatch(folderName);
    break;
  case "help":
  default:
    console.log(`${consoleContext}`);
}
